package controller

import (
	"user-center/dto"
	"user-center/query"
	"user-center/service"

	"github.com/androidsr/sc-go/model"
	"github.com/androidsr/sc-go/sgin"
	"github.com/gin-gonic/gin"
)

func init() {
	sgin.AddRouter(SysButtonsController{
		sysButtonsService: service.NewSysButtonsService(),
	})
}

type SysButtonsController struct {
	sysButtonsService service.SysButtonsService
}

// 查询
// @Router [get] [/sysbuttons/:id]
func (m SysButtonsController) Get(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysButtonsService.Get(id)
}

// 增加
// @Router [post] [/sysbuttons]
func (m SysButtonsController) Save(c *gin.Context, dto *dto.SysButtonsDTO) any {
	dto.Id = ""
	return m.sysButtonsService.Save(dto)
}

// 修改
// @Router [put] [/sysbuttons/edit]
func (m SysButtonsController) UpdateById(c *gin.Context, dto *dto.SysButtonsDTO) any {
	if dto.Id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysButtonsService.UpdateById(dto)

}

// 删除
// @Router [delete] [/sysbuttons/:id]
func (m SysButtonsController) DeleteById(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.sysButtonsService.DeleteById(id)
}

// 查询列表
// @Router [post] [/sysbuttons/page]
func (m SysButtonsController) QueryPage(c *gin.Context, query *query.SysButtonsQueryDTO) any {
	return m.sysButtonsService.QueryPage(query)
}

// 分页下拉
// @Router [post] [/sysbuttons/list]
func (m SysButtonsController) QuerySelect(c *gin.Context, query *model.SelectQueryDTO) any {
	return m.sysButtonsService.QueryList(query)
}
